/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import beans.BeanArancel;
import beans.BeanConsultaArancel;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author pcsijbug
 */
public class DAOArancel {

    PreparedStatement ptmt = null;
    ResultSet resulSet = null;
    Connection conexion = null;

    private Connection getConnection() throws SQLException {
        Connection conn;
        //BDConexFactory fact = new BDConexFactory(dataSource);
        conn = BDConexFactory.getInstance().getConnection();
        return conn;
    }

    /**
     *
     * @param consulta
     * @return
     * @throws SQLException
     */
    public List buscarArancelBD(BeanConsultaArancel consulta) throws SQLException {

        List listaAranceles = new ArrayList();

        try {

            conexion = getConnection();

            String sql = "SELECT * FROM PRODUCT WHERE PRODUCT_ID >= ?";

            ptmt = conexion.prepareStatement(sql);

            ptmt.setInt(1, Integer.parseInt(consulta.getDescripcion()));

            resulSet = ptmt.executeQuery();



            while (resulSet.next()) {
                BeanArancel ara = new BeanArancel();
                ara.setCodigoArancel(resulSet.getString("PRODUCT_CODE"));
                ara.setDescripcion(resulSet.getString("DESCRIPTION"));
                ara.setPrecioUnitario(resulSet.getBigDecimal("PURCHASE_COST"));
                listaAranceles.add(ara);

            }

        } catch (Exception e) {
        } finally {

            try {
                if (resulSet != null) {
                    resulSet.close();
                }
            } catch (SQLException e) {
                System.out.println("DAOArancel buscarArancelBD()"
                        + e.getMessage());


            } finally {

                try {
                    if (ptmt != null) {
                        ptmt.close();
                    }
                } catch (SQLException e) {
                    System.out.println("DAOArancel buscarArancelBD()"
                            + e.getMessage());


                }
                try {
                    if (conexion != null) {
                        conexion.close();
                        System.out.println("DAOArancel buscarArancelBD() cerrando conexion a  Base de Datos");

                    }
                } catch (SQLException e) {
                    System.out.println("DAOArancel buscarArancelBD()"
                            + e.getMessage());


                }

            }

            return listaAranceles;

        }



    }

    public List buscarArancel(BeanConsultaArancel consulta) {

        //simulacion de consulta a base de datos
        BeanArancel ara1 = new BeanArancel();
        ara1.setCodigoArancel("1212");
        ara1.setDescripcion("Pago por por tardanza");
        ara1.setPrecioUnitario(new BigDecimal("12.50"));


        BeanArancel ara2 = new BeanArancel();
        ara2.setCodigoArancel("1213");
        ara2.setDescripcion("Pago por por mala encuesta");
        ara2.setPrecioUnitario(new BigDecimal("32.50"));

        List listaAranceles = new ArrayList();
        listaAranceles.add(ara1);
        listaAranceles.add(ara2);


        return listaAranceles;
    }
}
